// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Example/Sample2DArrayTexture"
{
    Properties
    {
        _MyArr ("Tex", 2DArray) = "" {}
        _SliceRange ("Slices", Range(0,16)) = 6
        _UVScale ("UVScale", Float) = 1.0
    }
    SubShader
    {
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // 纹理数组并非在任何地方都可用，
            // 只能在它们所在的平台上编译着色器
            #pragma require 2darray
            
            #include "UnityCG.cginc"
            struct appdata_t {
                float4 vertex : POSITION;
                float4 customData : TEXCOORD0;
            };
            struct v2f {
                float4 vertex : SV_POSITION;
                float4 customData : TEXCOORD0;
            };

            float _SliceRange;
            float _UVScale;

            v2f vert (appdata_t v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.customData = v.customData;
                return o;
            }
            
            UNITY_DECLARE_TEX2DARRAY(_MyArr);

            half4 frag (v2f i) : SV_Target
            {
                return UNITY_SAMPLE_TEX2DARRAY(_MyArr, i.customData);
            }
            ENDCG
        }
    }
}